package org.ponly.cta4j.drawing.font;

import java.awt.Font;
import java.awt.geom.AffineTransform;

/**
 * 对字体进行随机旋转操作的随机字体库.
 *
 * @author vacoor
 * @since 1.0
 */
public class RotateRandomFontFamily extends RandomFontFamily {

    /**
     * {@inheritDoc}
     */
    @Override
    protected Font applyStyle(final Font font) {
        final Font styledFont = super.applyStyle(font);

        // rotate each letter by -0.33, +0.33 or about 20 degrees
        final float theta = (random.nextBoolean() ? 1 : -1) * random.nextFloat() / 3;

        // private DecimalFormat debug_fmt = new DecimalFormat();

        // rotate each letter by this angle
        final AffineTransform at = new AffineTransform();
        at.rotate(theta, random.nextDouble()/*x*/, random.nextDouble()/*y*/);
        return styledFont.deriveFont(at);
    }
}
